<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="../static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../static/plugins/layui/css/animate.min.css">
    <link rel="stylesheet" href="../static/plugins/layui/css/soulTable.css">
</head>
<style>
    .ok-body {
        padding: 10px
    }
</style>

<body>
<div class="ok-body">

    <div class="layui-row layui-form" >
        <div class="layui-col-lg3 layui-col-md4 layui-col-sm6">
            <div class="layui-inline">
                <label class="layui-form-label">用户</label>
                <div class="layui-input-inline" style="width: 190px;">
                    <select id="userId" name="userId" lay-search>
                        <option value="">选择用户</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-lg3 layui-col-md4 layui-col-sm6">
            <div class="layui-inline">
                <label class="layui-form-label">月份</label>
                <div class="layui-input-inline">
                    <input type="text" id="month" name="month"
                           class="layui-input" lay-verify="required" placeholder="请选择查询日期">
                </div>
            </div>
        </div>
        <div class="layui-col-lg1 layui-col-md1 layui-col-sm2 layui-col-xs3">
            <button class="layui-btn mgl-20" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</button>
        </div>
        <div class="layui-col-lg1 layui-col-md1 layui-col-sm2 layui-col-xs3">
            <button type="button" class="layui-btn layui-btn-warm" id="export"><i class="layui-icon">&#xe609;</i>导出</button>
        </div>
    </div>
    <hr class="layui-bg-orange">

    <table class="layui-hide" id="userGrade" lay-filter="userGrade"></table>
    <!--分页Div-->
    <div id="pageDiv" style="display: none"></div>

</div>

<script src="../static/plugins/layui/layui.js"></script>
<script src="../static/js/jquery-3.2.1.min.js"></script>
<script src="../static/js/jquery.base64.js"></script>
<script src="../static/js/device.js"></script>

<script th:inline="none">
    layui.config({
        base: '../static/plugins/layui/lay/soulTable/'
    }).extend({
        soulTable: 'soulTable'  // 模块别名
    });
    layui.use(['table','laypage','laydate','form','layer', 'soulTable'], function(){
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var soulTable = layui.soulTable;
        var laydate = layui.laydate;
        var now = new Date();
        var startTime = JJZ.FormatDate(now,'yyyyMM');

        laydate.render({
            elem: '#month'
            , type: 'month'
            ,max:JJZ.getNowFormatDate()
            , format: 'yyyyMM'
        });

        JJZ.initSelectShowField(JJZ.named('userId'),'/user/dataGrid','username',function (noErroe) {
            form.render();
        });


        var tableRenderObject = {
            elem: '#userGrade'
            ,title: '用户日常工作量积分'
            ,page:false
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: true
            ,limit:1000000
            ,height:665
            ,cols: [[
                {type: 'numbers', fixed: 'left'}
                ,{field:'userName', title:'姓名',align:'center'}
                ,{field:'masterFaultCount', title:'主维修次数',align:'center',templet:function (d) {
                        return d.masterFaultCount;
                    }}
                ,{field:'assistFaultCount', title:'参与维修次数',align:'center',templet:function (d){
                        return d.assistFaultCount;
                    }}
                ,{field:'faultCount',title:'维修积分',align:'center',templet:function (d){
                        if(d.assistFaultCount && d.assistFaultCount != 0){
                            return d.masterFaultCount + d.assistFaultCount/2;
                        }else{
                            return d.masterFaultCount;
                        }
                    }}
                ,{field:'finishTaskCount', title:'主维护检修数',align:'center',templet:function (d){
                    return d.finishTaskCount;
                    }}
                ,{field:'confirmTaskCount', title:'参与维护检修数',align:'center',templet:function (d){
                    return d.confirmTaskCount;
                    }}
                ,{field:'taskCount',title:'维护积分',align:'center',templet:function (d){
                        if(d.confirmTaskCount && d.confirmTaskCount != 0){
                            return d.finishTaskCount + d.confirmTaskCount/2;
                        }else{
                            return d.finishTaskCount;
                        }
                    }}
                ,{field:'total', title:'总积分',align:'center',templet:function (d) {
                        var faultGarde = 0;
                        if(d.assistFaultCount && d.assistFaultCount != 0){
                            faultGarde= d.masterFaultCount + d.assistFaultCount/2;
                        }else{
                            faultGarde= d.masterFaultCount;
                        }
                        var taskGarde = 0;
                        if(d.confirmTaskCount && d.confirmTaskCount != 0){
                            taskGarde= d.finishTaskCount + d.confirmTaskCount/2;
                        }else{
                            taskGarde= d.finishTaskCount;
                        }
                        return faultGarde+taskGarde;
                    }}
            ]]
            , excel:{
                filename:"员工工作量-"+startTime+".xlsx"
                ,cellType:'n'
            }
            ,done: function () {
                soulTable.render(this)
            }
        };
        var myTable;
        JJZ.requestData('/user/userGrade','month='+startTime,function (data) {
            tableRenderObject.data = data.records;
            // var records = data.records;
            // for(var index in records){
            //
            // }
            // console.log(data.records);
            myTable  = table.render(tableRenderObject);
        });

        form.on('submit(search)', function(data){
            var userId = $('#userId').val();
            var month = $('#month').val();
            var param = 'userId='+userId+'&month='+month;
            tableRenderObject.excel.filename="员工工作量-"+month+".xlsx";
            JJZ.requestData('/user/userGrade',param,function (data) {
                tableRenderObject.data = data.records;
                myTable  = table.render(tableRenderObject);
            });
            return false;
        });
        $('#export').on('click', function() {
            soulTable.export(myTable);
        })
    });

</script>

</body>
</html>